package cn.tedu.lonnghospital.appointment.controller;

import cn.tedu.lonnghospital.appointment.pojo.dto.AppointmentAddNewDTO;
import cn.tedu.lonnghospital.appointment.pojo.dto.AppointmentUpdateDTO;
import cn.tedu.lonnghospital.appointment.pojo.dto.DiagnosisAddNewDTO;
import cn.tedu.lonnghospital.appointment.pojo.vo.*;
import cn.tedu.lonnghospital.appointment.service.AppointmentService;
import cn.tedu.lonnghospital.appointment.service.DiagnosisService;
import cn.tedu.lonnghospital.appointment.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestController
@Api(tags = "就诊管理面板")
@RequestMapping("/diagnosis")
@Validated
@Slf4j
public class DiagnosisController {
    @Autowired
    DiagnosisService diagnosisService;

    @ApiOperationSupport(order = 100)
    @ApiOperation("新增就诊记录")
    @PostMapping("/addNew")
    public JsonResult addNew(@Valid DiagnosisAddNewDTO diagnosisAddNewDTO) {
        log.debug("开始处理【新增病历】请求，参数：{}", diagnosisAddNewDTO);
        diagnosisService.addNew(diagnosisAddNewDTO);
        log.debug("【新增病历】请求处理成功！");
        return JsonResult.ok();
    }

    @ApiOperationSupport(order = 300)
    @ApiOperation("根据就诊id修改病历")
    @PostMapping("/updateById")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "就诊ID", dataType = "long", required = true),
                    @ApiImplicitParam(name = "record", value = "门诊病历", dataType = "String", required = true)
            }
    )

    public JsonResult updateById(@Range(min = 1, message = "修改失败！就诊ID必须为正整数！")
                                 @RequestParam long id,
                                 @RequestParam String record) {
        log.debug("开始处理【根据就诊id修改病历】请求，参数：{},{}", id,record);
        diagnosisService.updateById(id,record);
        log.debug("【根据就诊id修改病历】请求处理成功！");
        return JsonResult.ok();
    }

    @ApiOperationSupport(order = 400)
    @ApiOperation("根据预约id查询基本信息")
    @GetMapping("/getAddNew")
    @ApiImplicitParam(name = "id", value = "预约ID", dataType = "long", required = true)
    public JsonResult getAddNew(@Range(min = 1, message = "查询失败！预约ID必须为正整数！")
                                @RequestParam long id) {
        log.debug("开始处理【根据预约id查询基本信息】请求，参数：{}", id);
        DiagnosisAddNewVO diagnosisAddNewVO = diagnosisService.getAddNew(id);
        log.debug("【根据预约id查询基本信息】请求处理成功！");
        return JsonResult.ok(diagnosisAddNewVO);
    }

    @ApiOperationSupport(order = 410)
    @ApiOperation("根据就诊id查询信息")
    @GetMapping("/getStandardById")
    @ApiImplicitParam(name = "id", value = "就诊ID", dataType = "long", required = true)
    public JsonResult getStandardById(@Range(min = 1, message = "查询失败！就诊ID必须为正整数！")
                                      @RequestParam long id) {
        log.debug("开始处理【根据就诊id查询信息】请求，参数：{}", id);
        DiagnosisStandardVO diagnosisStandardVO = diagnosisService.getStandardById(id);
        log.debug("【根据就诊id查询信息】请求处理成功！");
        return JsonResult.ok(diagnosisStandardVO);
    }

}
